import Vue from 'vue';
import Vuex from 'vuex';
import user from './modules/user';
import createVuexPersisted from 'vuex-persistedstate';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {},
  getters: {},
  mutations: {},
  actions: {},
  modules: {
    user,
  },
  plugins: [
    createVuexPersisted({
      reducer(val) {
        // val是state根模块
        return {
          // 将用户信息持久化
          user: {
            token: val.user.token,
            regionId: val.user.regionId,
            repair: val.user.repair,
            userId: val.user.userId,
            userName: val.user.userName,
          },
        };
      },
    }),
  ],
});
